/**
 * @file   : RollingWindow.ts
 * @time   : 13:57
 * @date   : 2025/3/7
 * @mail   : 9727005@qq.com
 * @creator: ShanDong Xiedali
 * @company: Less is more.Simple is best!
 */

import {ArrayHelper} from "../data/arrayHelper";

/**
 * @desc: 滑动窗口算法计算数组的移动平均值
 * @param {number[]} arr 数组
 * @param {number} windowSize 窗口大小
 * @return {number[]} 移动平均值数组
 */
export class RollingWindow {
    private data: number[] = [];

    constructor(arr: number[] = []) {
        this.data = arr;
    }

    /**
     * @desc: 向原始数组追加数据
     * @param {...number} num
     */
    appendData(...num: number[]) {
        this.data = this.data.concat(num);
    }

    /**
     * @desc: 计算移动平均值
     * @param {number} windowSize 窗口大小
     * @return {number[]} 移动平均值数组
     */
    getMovingAverage(windowSize: number): number[] {
        return ArrayHelper.getMovingAverage(this.data, windowSize);
    }
}


